package com.base.cn.platform.os.controller.classes.topic.type;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.entity.classes.topic.type.ClassesTopicType;
import com.base.cn.platform.os.service.course.classes.topic.type.ClassesTopicTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 班级话题类型
 *
 * @author zjh
 * @since 2019-5-17
 */
@Controller
@RequestMapping("/admin/classes/topic/type")
public class AdminTopicTypeController extends AdminBaseController {

    @Autowired
    private ClassesTopicTypeService classesTopicTypeService;
    /**
     * 话题类型列表
     * @return
     */
    @RequestMapping("/list")
    public String typeList(@RequestParam(value =  "classesId",required = false) BigDecimal classesId,Model model){
        model.addAttribute("classesId",classesId);
        return resultPage("/classes/topic/type/type-list");
    }


    /**
     * 话题类型列表内容
     * @return
     */
    @RequestMapping("/typeAjaxList")
    public String typeAjaxList(Model model,@RequestBody ClassesTopicType  param,@RequestParam("currentPage") int currentPage,
                               @RequestParam(value = "pageSize", required = false,defaultValue = "10") Integer pageSize){

        Map<String,Object> dataMap  =  classesTopicTypeService.findClassesTopicTypePage(param,currentPage,pageSize);
        model.addAttribute("dataMap",dataMap);
        return resultPage("classes/topic/type/ajax-type-list");
    }

    /**
     * 话题类型列表内容
     * @return
     */
    @RequestMapping("/saveTopicType")
    @ResponseBody
    public Map<String,Object> saveTopicType(@RequestParam("name") String name,
                                            @RequestParam(value = "id",required = false) BigDecimal id){
        ClassesTopicType classesTopicType = new ClassesTopicType();
        classesTopicType.setName(name);
        classesTopicType.setId(id);
        return classesTopicTypeService.saveClassesTopicType(classesTopicType);
    }

    /**
     * 新建类型
     * @return
     */
    @RequestMapping("/updateTopicTypeStatus")
    @ResponseBody
    public Map<String,Object> updateTopicTypeStatus(@RequestParam("ids") String ids,
                                                    @RequestParam(value = "status") int status){
        return classesTopicTypeService.updateTopicTypeStatus(ids,status);
    }
}
